home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / tool chest / development kits / mpw related / mpw script tips 1.1.1 / sample scripts / utol < prev    next >
Encoding:
Text File  |  1991-08-16  |  2.5 KB  |  79 lines

  1. #-------------------------------------------------------------------------------
  2. #    UtoL
  3. #    MPW Shell Script
  4. #    Written by Gina Cherry • August 16, 1991
  5. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  6. #    
  7. #    Usage: 
  8. #            UtoL [Window]
  9. #            
  10. #    Function:
  11. #            UtoL converts the selected text in the specified window from uppercase to lowercase.
  12. #
  13. #    Note: To add this command to the Edit menu, add the following line to your UserStartup file:
  14. #                    AddMenu Edit 'UtoL/5' 'UtoL "{Active}"'
  15. #-------------------------------------------------------------------------------
  16.  
  17. # Make sure there is no more than 1 parameter.
  18.     If {#} > 1                                                        
  19.         Echo "###Usage: {0} window" >> Dev:StdErr
  20.         Exit 1
  21.     End
  22.  
  23. # Do not exit on error.
  24.     Set Exit 0
  25.  
  26. # Initialize flag variable.
  27.     Set Flag 0
  28.  
  29. # Set Window to the parameter, or to the target window if no parameter was given.
  30.     If {#} == 1                                                         
  31.         Set Window "{1}"
  32.     Else
  33.         Set Window "{Target}"
  34.     End
  35.  
  36. # Set the variable Old to the selected text in the input file.  This command has the side effect of 
  37. #    checking whether the window is open.  Catenate will fail if Window is not an open window.  The 
  38. #    variable flag will be set to 1 if and only if the Catenate command is not successful.  
  39.     Begin
  40.         Set Old "`catenate "{Window}.§" ≥ Dev:Null || Set Flag 1`"    
  41.     End ≥ Dev:Null
  42.                                                                                                 
  43. #    Check if flag variable is set; if it is, write error message and exit with status 2.
  44.     If {Flag} == 1                                                                            
  45.         Echo "### {0}: {Window} is not a valid window" >> Dev: StdErr        
  46.         Exit 2
  47.     End
  48.  
  49. # If Old is the null string, no text was selected, so do nothing, and exit.
  50.     Exit If "{old}" == ""                                                                
  51.         
  52. # Otherwise, do the conversion.
  53.     # Save the value of NewWindowRect to restore later.
  54.         Set OldWindowRect NewWindowRect
  55.     
  56.     # Set NewWindowRect so that new windows are small.
  57.         Set NewWindowRect 0,0,100,100
  58.     
  59.     # Open a Temporary workspace.
  60.         Open -n {0}.Temp    
  61.     
  62.     # Restore old value of NewWindowRect.
  63.         Set NewWindowRect OldWindowRect
  64.  
  65.     # Translate all uppercase letters in the selected text to lowercase, and redirect the output to the 
  66.     #    temporary file.  
  67.         Translate A-Z a-z < "{Window}.§" > {0}.Temp                        
  68.                                                                                                 
  69.     # Select the entire temporary file.                                                                                            
  70.         Find •:∞ {0}.Temp    
  71.     
  72.     # Copy selection to the clipboard.
  73.         Copy § {0}.Temp    
  74.     
  75.     # Paste the converted text to Window, overwriting the old version of the text.
  76.         Paste § "{Window}"                                                            
  77.  
  78.     # Close the workspace; don't save changes.
  79.         Close -n {0}.Temp